<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\model\Menu;
use app\common\model\Role;
use app\common\model\Company;
use app\common\model\CheckList;
use app\common\model\UserNotify;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;

class Index extends Base
{
    protected $sort = [];

    /**
     * 显示资源列表
     *
     * @return string
     */
    public function index()
    {
        // $list = Company::where('id','>=',10000)->field('id,score')->select();
        // foreach ($list as $k => $v) {
        //     $v->score = CheckList::where('company_id', $v['id'])->value('one_score');
        //     $v->save();
        // }
        $rules = '';
        if ($this->admin['id'] != 1) {
            $rules = (new Role())->where('id', $this->admin['role_id'])->value('rules');
        }
        View::assign('menus', (new Menu())->getMenu($rules));
        View::assign('noticeCount', UserNotify::where('admin_part', 1)
            ->whereNotLike('admin_read_ids', '%' . $this->admin->id . '%')->count());
        return View::fetch();
    }

    public function welcome()
    {
        $da=[
            [
                'cate_id'=>1,
                'child'=>[
                    [
                        'desc'=>'不合格',
                        'images'=>'https://exp-picture.cdn.bcebos.com/c6b994775ddd884cb2f2e8916cef28066a01f612.jpg',
                        'points'=>20,
                        'topic_id'=>1,
                    ],
                    [
                        'desc'=>'不合格',
                        'images'=>'https://exp-picture.cdn.bcebos.com/c6b994775ddd884cb2f2e8916cef28066a01f612.jpg',
                        'points'=>20,
                        'topic_id'=>2,
                    ],
                    [
                        'desc'=>'不合格',
                        'images'=>'https://exp-picture.cdn.bcebos.com/c6b994775ddd884cb2f2e8916cef28066a01f612.jpg',
                        'points'=>20,
                        'topic_id'=>3,
                    ]
                ]
            ]
        ];
       // print_r(json_encode($da));die;
        View::assign('server_name', $_SERVER['SERVER_NAME']);
        return View::fetch();
    }

    public function clear_cache()
    {
        return Cache::clear() ? json(['code' => 1, 'msg' => '已清除']) : json(['code' => -1, 'msg' => '加载失败']);
    }
}
